<!DOCTYPE html>
<!--suppress ALL-->
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <base th:href="@{/}"><!-- 不用base就使用th:src="@{/js/jquery.min.js} -->
    <meta charset="UTF-8">
    <title>登录页面</title>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <script src="js/jquery.min.js"></script>
    <style>
        body {
            background-image: url("http://localhost:8070/design/img/2018764230.jpg");
        }

        /*login页面*/
        .container {
            border: 1px solid rgba(255, 255, 255, 0.3);
            margin-top: 100px;
            width: 60%;

            margin-left: 40%;

        }

        #l1, #l2, #l3, #l4 {
            color: #a11889;
        }

    </style>
<body>
<input type="hidden" id="msg" th:value="${msg}">
<div class="container">
    <div class="" style="width:70%; height: 60px;padding-top: 1px;">
        <h2 align="center" style="color: #a84e98;font-size: 25px">用户登录</h2>
    </div>
    <br><br>
    <form  name="myform" class="form-horizontal" role="form" id="username">
        <div class="form-group has-success">
            <label class="col-sm-2 col-md-2 control-label" id="l1">邮箱</label>
            <div class="col-sm-4 col-md-4">
                <input type="email" class="form-control" id="email" placeholder="请输入您的邮箱"/>
                <span></span>
            </div>
        </div>

        <div class="form-group has-success">
            <label class="col-sm-2 col-md-2 control-label" id="l2">密码</label>
            <div class="col-sm-4 col-md-4">
                <input type="password" class="form-control" id="password" placeholder="请输入您的密码"/>
                <span></span>
            </div>
        </div>

        <div class="form-group has-success">
            <label class="col-sm-2 col-md-2 control-label" id="l3">验证码</label>
            <div class="col-sm-4 col-md-4">
                <table style="width: 100%">
                    <tr>
                        <td><input type="text" class="form-control" id="code" placeholder="请输入验证码"/></td>
                        <td height="34px">
                            <img th:src="@{/getCode}" id="mycode" height="34px">
                        </td>
                        <td>
                            <a href="javascript:refreshCode()" style="color: #d35ebe;">看不清换一张</a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>


        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" class="btn btn-success" id="loginBtn" style="width: 150px">登录</button>
                <span style="margin-left: 20px"><a th:href="@{user/toResetPassword}">忘记密码？</a></span>
                <br>
                <input style="margin-top: 10px" type="button" class="btn btn-primary" value="邮箱登录" onclick="toEmail()">
                <span style="margin-top: 50px;margin-left: 80px"><a th:href="@{user/toReg}">免费注册</a></span>
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <font size="6" color="red">
                    <span></span>
                </font>
            </div>
        </div>
    </form>
</div>
</body>
<script>

    $("#regBtn").click(function () {
        location.href = "/design/user/toReg";
    });

    $("#loginBtn").click(function () {
        var email = $("#email").val();
        var password = $("#password").val();
        var code = $("#code").val();
        if (email == null || email == "") {
            alert("邮箱不能为空");
            return;
        }
        if (code.length!=4) {
            alert("验证码不正确");
            return;
        }
        if (password == null || password == "") {
            alert("密码不能为空");
            return;
        }
        $.post("/design/user/login", {email: email, password: password,code:code}, function (data) {
            if (data.state == 200) {
                location.href = "/design";
            } else {
                alert(data.message);
            }
        });
    });

    function refreshCode() {
        $("#mycode").attr("src", "getCode?time=" + new Date().getTime()+"");

    }
</script>
</html>